package com.wd.utils

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.preferencesDataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 *@Author Nick.wu
 *Date 2023/9/19
 */
private const val DATA_PREFERENCES_NAME = "data_preferences"
val Context.dataStore : DataStore<Preferences> by preferencesDataStore(
    name = DATA_PREFERENCES_NAME
)
private val USER_INFO = stringPreferencesKey("user_info")
class DataUtils(private val context: Context) {
    fun saveLoginInfo(json: String) {
        CoroutineScope(Dispatchers.Main).launch {
            context.dataStore.edit {
                it[USER_INFO] = json
            }
        }
    }

    fun getLoginInfo() {

    }
}